//
//  ToChannelViewController.m
//  BiologyLibrary
//
//  Created by King on 2019/5/30.
//  Copyright © 2019 youxh. All rights reserved.
//

#import "ToChannelViewController.h"
#import "RecordviewCell.h"
#import "NXfirststepViewController.h"
#import "NXNinthStepViewController.h"
#import "LBXScanViewStyle.h"
@interface ToChannelViewController ()

@end

@implementation ToChannelViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setNaviBarTitle:self.recordName];
    [self setNaviBarTitle:@"选择血样本"];
    _selectedRecordArr = [NSMutableArray arrayWithCapacity:0];
    // 创建一个自定义的按钮，并添加到导航条右侧。
    UIButton*_btnNaviRight = [CustomNaviBarView
                              createNormalNaviBarBtnByTitle:@"完成"
                              target:self
                              action:@selector(complete)];
    [self setNaviBarRightBtn:_btnNaviRight];
    [self setNaviBarLeftBtn:nil];
    
    
    _listview=[[UITableView alloc]initWithFrame:CGRectMake(10, 69 , fWidth_Current-20, fHeight_Current- 69 )];
    _listview.backgroundColor = [UIColor clearColor];
    _listview.separatorStyle = UITableViewCellSeparatorStyleNone;
    _listview.dataSource = self;
    _listview.delegate = self;
    _listview.showsVerticalScrollIndicator=NO;
    _listview.allowsMultipleSelectionDuringEditing = YES;
    [self.view addSubview:_listview];
    
}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
   
    [_listview setEditing:YES animated:YES];
    
    [_listview reloadData];
}



-(void)btnNaviLeftClick
{
    [self.navigationController popViewControllerAnimated:YES];
}

-(void)complete{
    if (self.selectBlock) {
        self.selectBlock(_selectedRecordArr);
    }
    [self dismissViewControllerAnimated:YES completion:NULL];
}


#pragma mark - UITableViewDataSource
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return 1;
    
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return [self.NewRecordArray count];//返回标题数组中元素的个数来确定分区的个数
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 40;
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section==0) {
        return 10;
    }else{
        return 0.1;
        
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.1;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView*headview=[[UIView alloc]initWithFrame:CGRectMake(0, 0, fWidth_Current, 18)];
    headview.backgroundColor=[UIColor clearColor];
    return headview;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView*headview=[[UIView alloc]initWithFrame:CGRectMake(0, 0, fWidth_Current, 18)];
    headview.backgroundColor=[UIColor clearColor];
    return headview;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"CustomCell";
    RecordviewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"RecordviewCell" owner:self options:nil];
    
    for (id oneObject in nib)
    {
        if ([oneObject isKindOfClass:[RecordviewCell class]])
        {
            cell = (RecordviewCell *)oneObject;
        }
    }
    cell.backgroundColor=[UIColor colorWithRed:0.16 green:0.19 blue:0.24 alpha:1.0];
    cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
    
    Record *tempRecord = (Record *)[self.NewRecordArray objectAtIndex:indexPath.section];
    
    cell.titlelab.text = tempRecord.recordId;
    cell.steplab.text = [NSString stringWithFormat:@"第%ld步",tempRecord.savedStepCount];
    return cell;
    
}
#pragma mark - UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    Record *tempRecord = (Record *)[self.NewRecordArray objectAtIndex:indexPath.section];
    
        [_selectedRecordArr addObject:tempRecord];
    
}
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(nonnull NSIndexPath *)indexPath
{
    Record *tempRecord = (Record *)[self.NewRecordArray objectAtIndex:indexPath.section];
    
    [_selectedRecordArr removeObject:tempRecord];
    
}





- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
